/**
 * 
 */
$(initTeamUser());
function initTeamUser(){
	$.ajax({
		type : "post",
		url : "GetTeamActorServlet",
		data :{teamID:teamID},
		dateType : "json",
		success : function(data) {
			var jsondata = eval('(' + data + ')');
			var arrayNode=$("#add-actor-content");
			arrayNode.children().remove();
			if(jsondata.tUserArray.length==0){
				var newActorNode=$("<div></div>").addClass("invite-item");
				newActorNode.append("<img class=\"avatar\" src=\"../images/avatar.gif\">"+
									"<div class=\"invite-field\">"+
									"<input name=\"actot_name\" type=\"text\" class=\"invite-email no-border\""+
										"placeholder=\"请输入新成员的邮箱\">"+
									"<div class=\"invite-role-field\"></div>"+
									"<input name=\"actor_desc\" type=\"text\" class=\"invite-comment no-border\""+
										"placeholder=\"添加成员备注（可选）\" data-validate=\"length:0,128\""+
									"data-validate-msg=\"成员备注最长128个字符\"></div>");
				$("#add-actor-content").append(newActorNode);
			}
			$.each(jsondata.tUserArray,function (n,v){
				var newActorNode=$("<div></div>").addClass("invite-item");
				newActorNode.append("<img class=\"avatar\" src=\"../userIcons/"+v.userIcon+"\">"+
									"<div class=\"invite-field\">"+
									"<input name=\"actot_name\" type=\"text\" class=\"invite-email no-border\""+
										"placeholder=\"请输入新成员的昵称\" value=\""+v.userNickName+"\">"+
									"<div class=\"invite-role-field\"></div>"+
									"<input name=\"actor_desc\" type=\"text\" class=\"invite-comment no-border\""+
										"placeholder=\"添加成员备注（可选）\" data-validate=\"length:0,128\""+
									"data-validate-msg=\"成员备注最长128个字符\" value=\""+v.desc+"\"></div>");
				newActorNode.append("<a class=\"del-invite\" onclick=\"delActor($(this))\" href=\"javascript:;\">删除</a>");
				arrayNode.append(newActorNode);
			});
		},
		error : function() {
			// TODO do something
		}
	});
}
function delActor(delNode){
	delNode.parent("div.invite-item").remove();
	var insNode=$("#add-actor-content").children("div.invite-item");
	if(insNode.length==1){
		insNode.children("a.del-invite").remove();
	}
}
function addActor(){
	var newActorNode=$("<div></div>").addClass("invite-item");
	newActorNode.append("<img class=\"avatar\" src=\"../images/avatar.gif\">"+
						"<div class=\"invite-field\">"+
						"<input name=\"actot_name\" type=\"text\" class=\"invite-email no-border\""+
							"placeholder=\"请输入新成员的昵称\">"+
						"<div class=\"invite-role-field\"></div>"+
						"<input name=\"actor_desc\" type=\"text\" class=\"invite-comment no-border\""+
							"placeholder=\"添加成员备注（可选）\" data-validate=\"length:0,128\""+
						"data-validate-msg=\"成员备注最长128个字符\"></div>");
	var arrayNode=$("#add-actor-content").append(newActorNode);
	arrayNode.children(".invite-item").each(function (){
		if($(this).children(".del-invite").length==0){
			$(this).append("<a class=\"del-invite\" onclick=\"delActor($(this))\" href=\"javascript:;\">删除</a>");
		}
	});
}
function updateCoopUser(){
	var userName=new Array();
	var userDesc=new Array();
	$(":input").each(function(n,b){
		var inputName=$(b).attr("name");
		if(inputName=='actot_name'){
			userName.push($(b).val());
		}
		if(inputName=='actor_desc'){
			userDesc.push($(b).val());
		}
	});
	$.ajax({
		type : "post",
		url : "UpdateCoopUserServlet",
		data :{teamID:teamID,userName:userName,userDesc:userDesc},
		dateType : "json",
		success : function(data) {
			var jsondata = eval('(' + data + ')');
			if(jsondata.isSuccess=="true"){
				if (confirm("修改 成功!")) {
					//跳转至协作学习平台首页
					initTeamUser();
				}
			}else{
				confirm("操作失败 ! 请重试...");
			}
		},
		error : function() {
			// TODO do something
		}
	});
}
function back(){
	window.history.go(-1);
}